package com.morningstar.flow.antvX6.node;

import com.alibaba.fastjson2.JSON;
import com.morningstar.flow.antvX6.common.Node;
import com.morningstar.flow.antvX6.common.NodeParser;
import com.morningstar.flow.flowable.task.CopyServiceTask;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.ServiceTask;

import java.util.HashMap;

/**
 * 抄送任务节点
 * @author Admin
 */
@Getter
@Setter
public class NodeCopyService extends Node implements NodeParser {

    public static final String TYPE = "node_copy_service";

    @Override
    public String getNodeType() {
        return TYPE;
    }

    @Override
    public String getNodeName() {
        if (this.getData() != null && StringUtils.isNotBlank(this.getData().getLabel())) {
            return this.getData().getLabel();
        }
        return "抄送节点";
    }

    @Override
    public void convertAndAdd(Process process) {
        ServiceTask serviceTask = new ServiceTask();
        serviceTask.setId(this.getCName());
        serviceTask.setName(this.getNodeName());
        serviceTask.setImplementationType("class");
        serviceTask.setImplementation(CopyServiceTask.class.getCanonicalName());
        serviceTask.setAsynchronous(false);
        process.addFlowElement(serviceTask);
    }


    @Override
    public Node parse(HashMap<String, Object> cell) {
        return JSON.parseObject(JSON.toJSONString(cell), NodeCopyService.class);
    }
}
